#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    QTabWidget* tabWidget1 = new QTabWidget(this);

    std::vector<QWidget*> tabPageManager;
    std::vector<QTextEdit*> textEditManager;
    std::vector<QVBoxLayout*> vBoxLayoutManager;

    for(int i=0;i<3;i++)
    {
        tabPageManager.push_back(new QWidget(tabWidget1));//创建页面
        vBoxLayoutManager.push_back(new QVBoxLayout(tabPageManager[i]));//创建页面布局，父对象为对应的页面对象，生命周期由对应的页管理
        textEditManager.push_back(new QTextEdit(tabPageManager[i]));

        // QVBoxLayout* vBoxLayout = new QVBoxLayout(tabPageManager[i]);
        vBoxLayoutManager[i]->addWidget(textEditManager[i]);
        tabPageManager[i]->setLayout(vBoxLayoutManager[i]);
    }


    for(std::vector<QWidget*>::iterator it = tabPageManager.begin(); it != tabPageManager.end(); ++it)
        tabWidget1->addTab( *it, QString("%1.c").arg( std::distance( tabPageManager.begin(), it ) ) );

    QVBoxLayout* vBoxLayout_tab = new QVBoxLayout(this);
    vBoxLayout_tab->addWidget(tabWidget1);

    this->setLayout(vBoxLayout_tab);

}

Widget::~Widget()
{
    delete ui;
}
